package com.spring.cloud.study.gateway.error;

import org.springframework.boot.autoconfigure.web.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: 齐丹枫
 * Date: 2018/3/2
 * Time: 15:42
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Component
public class MyDefaultErrorAttributes extends DefaultErrorAttributes{

    private final static String ERROR_CODE = "javax.servlet.error.status_code";

    @Override
    public Map<String, Object> getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) {

        Map<String, Object> result = super.getErrorAttributes(requestAttributes, includeStackTrace);
      //  Throwable error = super.getError(requestAttributes);
        System.out.println(result);
        Map<String, Object> r = new HashMap<>();
        r.put("code",result.get("status"));
        r.put("message","服务异常，请稍后重试");

        return r;
    }
}
